package com.leo;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.net.URL;

/**
 * @ClassName FxApplication
 * @Description
 * @Author wangss
 * @date 2020.06.26 22:10
 * @Version 1.0
 */
public class FxApplication extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        // 主题切换
//        Application.setUserAgentStylesheet(Application.STYLESHEET_CASPIAN);

        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: linear-gradient(to bottom right, #f0fff0, #add8e6)");

        VBox leftBox = leftLayout();

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/right.fxml"));
        VBox rightBox = fxmlLoader.load();

        anchorPane.getChildren().addAll(leftBox, rightBox);
        AnchorPane.setTopAnchor(leftBox, 50d);
        AnchorPane.setTopAnchor(rightBox, 50d);
        AnchorPane.setLeftAnchor(leftBox, 20d);
        AnchorPane.setLeftAnchor(rightBox, 420d);

        Scene scene = new Scene(anchorPane);
        URL url = this.getClass().getResource("/css/mycss.css");
        scene.getStylesheets().add(url.toExternalForm());

        primaryStage.setScene(scene);
        primaryStage.setTitle("css样式");
        primaryStage.setWidth(800d);
        primaryStage.setHeight(800d);
        primaryStage.show();
    }

    private VBox leftLayout() {
        VBox vBox = new VBox(20);

        Button button = new Button("button");
        button.setId("litton");
        button.setOnAction(event -> {
            System.out.println("我被点击了");
        });
        Label label = new Label("label");
        TextField tf = new TextField("textfield");
        tf.getStyleClass().add("my_css");

        vBox.getChildren().addAll(button, label, tf);

        return vBox;
    }
}
